
$(function() {
	//窗口滚动 隐藏头部
	var oldOffSet = $(window).scrollTop(); //偏移量
	var direction = true //滑动方向
	var status = true //菜单显示状态
	var distance = 0 //滑动距离
	var eleHeight = parseInt($(".header-top").css("height")) //菜单高度

	function showHeader() {
		status = true
		$(".header-top").stop()
		$(".header-top").animate({
			height: '0.8rem'
		}, 400)
	}

	function hideHeader() {
		status = false
		$(".header-top").stop()
		$(".header-top").animate({
			height: 0
		}, 300)
	}
	$(window).scroll(function() {
		var newOffSet = document.documentElement.scrollTop + document.body.scrollTop
//		console.log(newOffSet)
		//下滑 隐藏
		if (newOffSet < 0) {
			var top = (-newOffSet).toString() + "px"
			$(".header").css("top", top)
		} else {
			$(".header").css("top", "0")
			if ($(".menu").length > 0) {
				if (newOffSet > oldOffSet) {
					if(status && distance >= eleHeight) {
						hideHeader()
//						console.log("hide")
					}
					if (direction) {
						direction = false
						distance = 0	
					}
//					console.log('up', direction, distance, distance >= parseInt($(".header-top").css("height")))
				} else {
					if(!status) {
						showHeader()
//						console.log('show')
					}
					if (!direction) {
						direction = true
						distance = 0	
					}
//					console.log('down', direction)
				}
			}
		}
		
		distance += newOffSet - oldOffSet
		oldOffSet = newOffSet
	});
})